package com.carAnalysisAdmin.system.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.carAnalysisAdmin.system.domain.SysParkSpot;
import com.carAnalysisAdmin.system.mapper.SysDictDataMapper;
import com.carAnalysisAdmin.system.mapper.SysParkSpotMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.carAnalysisAdmin.system.mapper.SysParkFloorMapper;
import com.carAnalysisAdmin.system.domain.SysParkFloor;
import com.carAnalysisAdmin.system.service.ISysParkFloorService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 楼层管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-14
 */
@Service
public class SysParkFloorServiceImpl implements ISysParkFloorService 
{
    @Autowired
    private SysParkFloorMapper sysParkFloorMapper;
    @Autowired
    private SysParkSpotMapper sysParkSpotMapper;
    @Autowired
    private SysDictDataMapper dictDataMapper;

    /**
     * 查询楼层管理
     * 
     * @param id 楼层管理主键
     * @return 楼层管理
     */
    @Override
    public SysParkFloor selectSysParkFloorById(Long id)
    {
        return sysParkFloorMapper.selectSysParkFloorById(id);
    }

    /**
     * 查询楼层管理列表
     * 
     * @param sysParkFloor 楼层管理
     * @return 楼层管理
     */
    @Override
    public List<SysParkFloor> selectSysParkFloorList(SysParkFloor sysParkFloor)
    {
        return sysParkFloorMapper.selectSysParkFloorList(sysParkFloor);
    }

    /**
     * 新增楼层管理
     * 
     * @param sysParkFloor 楼层管理
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class) // 可选：指定回滚异常类型
    public int insertSysParkFloor(SysParkFloor sysParkFloor, Integer numPark) {
        int rowNum = sysParkFloorMapper.insertSysParkFloor(sysParkFloor);
        String defaultSpice = dictDataMapper.selectDictLabel("default_spice", "default_spice");
        BigDecimal defaultSpices = new BigDecimal(defaultSpice);
        if (numPark !=null && numPark > 0 ){
            SysParkSpot sysParkSpot;
            for (int i = 0; i < numPark; i++ ){
                sysParkSpot = new SysParkSpot();
                sysParkSpot.setCode(sysParkFloor.getId()+"-"+(i+1));
                sysParkSpot.setFloorId(sysParkFloor.getId().intValue());
                sysParkSpot.setPrice(defaultSpices);
                sysParkSpotMapper.insertSysParkSpot(sysParkSpot);
            }
        }
        return rowNum;
    }

    /**
     * 修改楼层管理
     * 
     * @param sysParkFloor 楼层管理
     * @return 结果
     */
    @Override
    public int updateSysParkFloor(SysParkFloor sysParkFloor)
    {
        return sysParkFloorMapper.updateSysParkFloor(sysParkFloor);
    }

    /**
     * 批量删除楼层管理
     * 
     * @param ids 需要删除的楼层管理主键
     * @return 结果
     */
    @Override
    public int deleteSysParkFloorByIds(Long[] ids)
    {
        return sysParkFloorMapper.deleteSysParkFloorByIds(ids);
    }

    /**
     * 删除楼层管理信息
     * 
     * @param id 楼层管理主键
     * @return 结果
     */
    @Override
    public int deleteSysParkFloorById(Long id)
    {
        return sysParkFloorMapper.deleteSysParkFloorById(id);
    }

    @Override
    public SysParkFloor selectSysParkFloorBySpotCode(String spotCode) {
        return sysParkFloorMapper.selectSysParkFloorBySpotCode(spotCode);
    }
}
